package com.lh.elevator;

public class ElevatorMain {

    public static void main(String[] args) {

        Elevator elevator = new Elevator();
        elevator.setHeight(20);
        elevator.setUpQueue(new ElevatorQueue());
        elevator.setDownQueue(new ElevatorQueue());
        elevator.setStatus(0);
        User user = new User();
        user.setElevator(elevator);
        user.setStatus(1);
        user.setCurrentHeight(1);
        user.setNeedHeight(20);

        User user1 = new User();
        user1.setElevator(elevator);
        user1.setStatus(2);
        user1.setCurrentHeight(10);
        user1.setNeedHeight(1);

        if (elevator.getStatus() == 0) {
            if (elevator.getHeight() > user.getCurrentHeight()) {
                elevator.setStatus(2);
            }
            if (elevator.getHeight() < user.getCurrentHeight()) {
                elevator.setStatus(1);
            }
            if (elevator.getHeight() == user.getCurrentHeight()) {
                elevator.setStatus(user.getStatus());
            }
        }

        ElevatorQueue downQueue = elevator.getDownQueue();
        ElevatorQueue upQueue = elevator.getUpQueue();
        while (!downQueue.isEmpty() || !upQueue.isEmpty()) {
            removeElevator(elevator, upQueue, 1);
            removeElevator(elevator, downQueue, 2);

        }


    }

    private static void removeElevator(Elevator elevator, ElevatorQueue upQueue, Integer i) {
        if (elevator.getStatus() == i) {
            while (!upQueue.isEmpty()) {
                Integer remove = upQueue.remove(elevator.getHeight(), i);
                System.out.println("已到楼层:"+remove);
                elevator.setHeight(remove);
            }
            if (i == 1) {
                elevator.setStatus(2);

            }
            if (i == 2) {
                elevator.setStatus(1);
            }
        }
    }


}
